package edu.zsl.service.impl;

import edu.zsl.mapper.CourseMapper;
import edu.zsl.pojo.Course;
import edu.zsl.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {
    private final CourseMapper courseMapper;
    @Autowired
    public CourseServiceImpl(CourseMapper courseMapper) {this.courseMapper = courseMapper;}

    //查询所有课程
    @Override
    public List<Course> getAllCourses() {
        return courseMapper.getAll();
    }

    //添加课程
    @Override
    public void insertCourse(Course course) {
        LocalDateTime now = LocalDateTime.now();
        course.setCreateBy(1);
        course.setCreateTime(now);
        courseMapper.insertCourse(course);
    }

    //通过课程号查询课程
    @Override
    public Course getCourseById(Integer id) {
        Course course = courseMapper.getById(id);
        return course;
    }

    //更新课程
    @Override
    public void updateCourse(Course course) {
        course.setUpdateBy(1);
        course.setUpdateTime(LocalDateTime.now());
        courseMapper.update(course);
    }

    //删除课程
    @Override
    public void deleteCourseById(Integer id) {
        courseMapper.deleteCourseById(id);
    }

    //查询某一课程的学生选课情况
    @Override
    public List<Course> getCourseStudentDetails(Integer id){
        return courseMapper.getCourseStudentDetails(id);
    }
}
